<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        [v-cloak] {
            display: none;
        }
        .tab ul{
            overflow: hidden;
            padding: 0;
            margin: 0;
        }
        .tab ul li {
            box-sizing: border-box;
            padding: 0;
            float: left;
            width: 100px;
            height: 45px;
            line-height: 45px;
            list-style: none;
            text-align: center;
            border-top: 1px solid blue;
            border-right: 1px solid blue;
            cursor: pointer;
        }
        .tab ul li:first-child{
            border-left: 1px solid blue;
        }
        .tab ul li.active{
            background-color: orange;
        }
        .tab div{
            width: 500px;
            height: 300px;
            display: none;
            text-align: center;
            font-size: 30px;
            line-height: 300px;
            border: 1px solid blue;
            border-top: 0;
        }
        .tab div img{
            width: 100%;
            height: 100%;
        }
        .tab div.current{
            display: block;
        }
    </style>
</head>
<body>
    <h2>Vue案例-Tab选项卡</h2>
        <div id="app">
            <div class="tab">
                <ul>
                    <li @click="change(index)" :class='currentIndex===index?"active":""' v-for='(item,index) in list' :key='item.id'>{{item.title}}</li>
                </ul>
                <div :class='currentIndex===index?"current":""' v-for='(item,index) in list' :key='item.id'>
                    <img :src="item.path" alt="001">
                </div>
            </div>
        </div>
</body>
<script src="./js/vue.js"></script>
<script>
    var vm = new Vue({
        el: '#app',
        data: {
            list: [{
                id: 1,
                title: 'apple',
                path: './image/001.jpg'
            },{
                id: 2,
                title: 'orange',
                path: './image/002.jpg'
            },{
                id: 3,
                title: 'lemon',
                path: './image/003.jpg'
            }],
            currentIndex: 0 //选项卡当前选中的索引
        },
        methods:{
            change:function(index){
                //在这里实现选项卡切换效果  本质就是操作类名
                this.currentIndex = index;
            }
        }
    })
    /*
        总结：
            v-for遍历对象          
                     <div v-for='(value,key,index) in object'></div>

            v-if和v-for结合使用
                    <div v-if='value===12' v-for='(value,key,index) in object'></div>
    */
</script>
</html>